package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.LExebill;
import com.ruoyi.system.service.ILExebillService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 派工单主Controller
 *
 * @author zyb
 * @date 2022-01-03
 */
@RestController
@RequestMapping("/system/exebill")
public class LExebillController extends BaseController
{
    @Autowired
    private ILExebillService lExebillService;

    /**
     * 查询派工单主列表
     */
    @PreAuthorize("@ss.hasPermi('system:exebill:list')")
    @GetMapping("/list")
    public TableDataInfo list(LExebill lExebill)
    {
        startPage();
        List<LExebill> list = lExebillService.selectLExebillList(lExebill);
        return getDataTable(list);
    }

    /**
     * 导出派工单主列表
     */
    @PreAuthorize("@ss.hasPermi('system:exebill:export')")
    @Log(title = "派工单主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LExebill lExebill)
    {
        List<LExebill> list = lExebillService.selectLExebillList(lExebill);
        ExcelUtil<LExebill> util = new ExcelUtil<LExebill>(LExebill.class);
        util.exportExcel(response, list, "派工单主数据");
    }

    /**
     * 获取派工单主详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:exebill:query')")
    @GetMapping(value = "/{billid}")
    public AjaxResult getInfo(@PathVariable("billid") Long billid)
    {
        return AjaxResult.success(lExebillService.selectLExebillByBillid(billid));
    }

    /**
     * 新增派工单主
     */
    @PreAuthorize("@ss.hasPermi('system:exebill:add')")
    @Log(title = "派工单主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LExebill lExebill)
    {
        return toAjax(lExebillService.insertLExebill(lExebill));
    }

    /**
     * 修改派工单主
     */
    @PreAuthorize("@ss.hasPermi('system:exebill:edit')")
    @Log(title = "派工单主", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LExebill lExebill)
    {
        return toAjax(lExebillService.updateLExebill(lExebill));
    }

    /**
     * 删除派工单主
     */
    @PreAuthorize("@ss.hasPermi('system:exebill:remove')")
    @Log(title = "派工单主", businessType = BusinessType.DELETE)
	@DeleteMapping("/{billids}")
    public AjaxResult remove(@PathVariable Long[] billids)
    {
        return toAjax(lExebillService.deleteLExebillByBillids(billids));
    }

    @GetMapping(value = "/billcode")
    public AjaxResult getBillCode()
    {
        return AjaxResult.success(lExebillService.getBillCode());
    }
}
